package com.ai.service.made.impl;

import com.ai.common.constant.AlgorithmConstant;
import com.ai.entity.network.SiToDsSysMessage;
import com.ai.mapper.plc.SiToDsMapper;
import com.ai.networking.netty.service.SendMessage;
import com.ai.service.made.ISISignalService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.time.LocalDateTime;

@Service
public class ISISignalServiceImpl implements ISISignalService {

    @Resource
    private SiToDsMapper siToDsMapper;
    @Override
    public void receiveSignal(SiToDsSysMessage message) {
        message.setCreateTime(LocalDateTime.now());
        if (message.getTeleNo().equals(AlgorithmConstant.SI_TO_DS_DEFECT_DETECTION_STATUS)){
//            SiToDsSysMessage siToDsSysMessage = siToDsMapper.selectFaultState();
//            if (!message.equalsByFaultState(siToDsSysMessage)){
            siToDsMapper.save(message);
            String code = "AG_C";
            SendMessage.sendMessage(code,message);
//            }
        }else if (message.getTeleNo().equals(AlgorithmConstant.SI_TO_DS_DEFECT_DETAILS)){
//            SiToDsSysMessage siToDsSysMessage = siToDsMapper.selectDefect();
//            if (!message.equalsByDefect(siToDsSysMessage)){
            siToDsMapper.save(message);
            String code = "AG_C";
            SendMessage.sendMessage(code,message);
//            }
        }else if (message.getTeleNo().equals(AlgorithmConstant.SI_TO_DS_DEFECT_OFFSET)){
//            SiToDsSysMessage siToDsSysMessage = siToDsMapper.selectStraightDeviation();
//            if (!message.equalsByStraightDeviation(siToDsSysMessage)){
            siToDsMapper.save(message);
            String code = "AG_C";
            SendMessage.sendMessage(code,message);
//            }
        }
    }
}
